package com.example.touch.domain;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.widget.Toast;

import com.example.touch.communication.entities.Notification;

/**
*
* @author pla
*/
public class NotificationAction extends AbstractActivityAction<Notification>
{
	private boolean isToast;
	
	public NotificationAction(Activity activity, Notification action) 
	{
		super(activity, action);
		this.isToast = true;
	}
	
	public NotificationAction(Activity activity, Notification action, boolean isToast) 
	{
		super(activity, action);
		this.isToast = isToast;
	}

	@Override
	protected void executeAction() 
	{
		Activity activity = getActivity();
		String msg = getAction().getMessage();
		
		if(isToast)
			Toast.makeText(activity, msg, Toast.LENGTH_SHORT).show();
		else
			showAlertDialog(activity, msg);
	}

	@SuppressWarnings("deprecation")
	private void showAlertDialog(Activity activity, String msg)
	{
		AlertDialog ad = new AlertDialog.Builder(activity).create();
		ad.setCancelable(false); // blocks the BACK button
		ad.setMessage(msg);
		
		ad.setButton("OK", new DialogInterface.OnClickListener() 
		{
		    @Override
		    public void onClick(final DialogInterface dialog, final int which) 
		    {
		        dialog.dismiss();                    
		    }
		});
		
		ad.show();
	}
}
